package com.ideal.frame.entity;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @Author: jin
 * @CreateTime: 2020-02-18 14:15
 * @Description: 树
 */
@Data
public class TreeModel<T> implements Comparable{
    private String nodeId;
    private T node;
    private String parentId;
    private String label;
    private int sort;
    private List<TreeModel> children;

    private TreeModel(Builder<T> builder) {
        setNodeId(builder.nodeId);
        setNode(builder.node);
        setParentId(builder.parentId);
        setLabel(builder.label);
        setSort(builder.sort);
        setChildren(builder.children);
    }

    @Override
    public int compareTo(Object o) {
        return this.getSort() - ((TreeModel)o).getSort();
    }

    public static final class Builder<T> {
        private String nodeId;
        private T node;
        private String parentId;
        private String label;
        private int sort;
        private List<TreeModel> children;

        public Builder() {
        }

        public Builder nodeId(String val) {
            nodeId = val;
            return this;
        }

        public Builder node(T val) {
            node = val;
            return this;
        }

        public Builder parentId(String val) {
            parentId = val;
            return this;
        }

        public Builder label(String val) {
            label = val;
            return this;
        }

        public Builder sort(int val) {
            sort = val;
            return this;
        }

        public Builder children(List<TreeModel> val) {
            children = val;
            return this;
        }

        public TreeModel build() {
            return new TreeModel(this);
        }
    }
}
